import Taro, { useDidShow } from "@tarojs/taro";
import { View, Image } from "@tarojs/components";
import { Empty, SubmitBar } from "@antmjs/vantui";
import {isEmpty} from 'lodash'
import { useState } from "react";
import "./detail.scss";

const Detail = () => {
  Taro.setNavigationBarTitle({ title: "商品详情" });
  const datas = Taro.getStorageSync("_id");
  // const [data, setData] = useState([]);
  const [commodity, setCommodity] = useState([]);

  useDidShow(() => {
    detail();
  });

  const detail = () => {
    Taro.cloud
      .callFunction({
        name: "logins",
        data: {
          $url: "getSaleContent",
          _id: datas
        }
      })
      .then((res: any) => {
        setCommodity(res.result.data);
        // setData(res.result.data);
      });
  };

  //是对象
  const Commodity =
    !isEmpty(commodity)  ? (
      <View className="commodity">
        <Image src={commodity.image[0]} className="image" />
        {/* <View className="price">{content.price}</View> */}
        <View className="name">{commodity.name}</View>
        <View className="order">
          <SubmitBar price={commodity.price * 100} buttonText="提交订单" />
        </View>
      </View>
    ) : (
      <Empty description='没有更多内容了' />
    );

  return (
    <View className="box">
      <View>{Commodity}</View>
      {/* <View>
        <SubmitBar price={3050} buttonText="提交订单" />
      </View> */}
    </View>
  );
};
export default Detail;
